require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#perfectUserInfo",
    data:{
        pop:{
            question: "确定要跳过此步骤？",
            show: false
        },
        list:{
            loginUid:userInfo.id,
            sex:"",
            birthday:""
        }
    },
    mounted:function(){
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //退货显示框
        getIsClassify:function(){
            this.pop.show=!this.pop.show;
        },
        getSex:function (sex) {
            this.list.sex=sex;
        },
        //日期选择
        getData:function(){
            // 初始化时间
            var that=this;
            var now = new Date();
            that.nowYear = now.getFullYear();
            that.nowMonth = now.getMonth() + 1;
            that.nowDate = now.getDate();
            var iosSelect = new IosSelect(3,
                [yearData, monthData, dateData],
                {
                    itemHeight: 30,
                    oneLevelId: that.nowYear,
                    twoLevelId: that.nowMonth,
                    threeLevelId: that.nowDate ,
                    // showLoading: true,
                    callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
                        that.list.birthday=selectOneObj.value.replace(/[^0-9]/ig,"")+"-"+selectTwoObj.value.replace(/[^0-9]/ig,"")+"-"+selectThreeObj.value.replace(/[^0-9]/ig,"");
                        console.log(that.list.birthday)
                    }
                });
        },
        //完善生日，性别
        setFirstInfo:function(){
            var that=this;
            console.log(that.list)
            this.ajax({url:"/user/setFirstInfo",data:that.list,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    userInfo.sex=that.list.sex;
                    userInfo.birthday=that.list.birthday;
                    sessionStorage.setItem("userInfo",JSON.stringify(userInfo));
                    that.getNext();
                }else{
                    vm.$refs.prompt.toast("信息保存失败！");
                }
            });
        },
        getNext:function(){
            location.href="/user/addName";
        }
    },
    watch:{

    }
});

// 数据初始化
var yearData = function(callback) {
    callback(formatYear(vm.nowYear))
};
var monthData = function (year, callback) {
    callback(formatMonth());
};
var dateData = function (year, month, callback) {
    if (/^(1|3|5|7|8|10|12)$/.test(month)) {
        callback(formatDate(31));
    }
    else if (/^(4|6|9|11)$/.test(month)) {
        callback(formatDate(30));
    }
    else if (/^2$/.test(month)) {
        if (year % 4 === 0 && year % 100 !==0 || year % 400 === 0) {
            callback(formatDate(29));
        }
        else {
            callback(formatDate(28));
        }
    }
    else {
        throw new Error('month is illegal');
    }
};
function formatYear (nowYear) {
    var arr = [];
    for (var i = nowYear - 45; i <= nowYear; i++) {
        arr.push({
            id: i + '',
            value: i + '年'
        });
    }
    return arr;
}
function formatMonth () {
    var arr = [];
    for (var i = 1; i <= 12; i++) {
        arr.push({
            id: i + '',
            value: i + '月'
        });
    }
    return arr;
}
function formatDate (count) {
    var arr = [];
    for (var i = 1; i <= count; i++) {
        arr.push({
            id: i + '',
            value: i + '日'
        });
    }
    return arr;
}